package com.ruoyi.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.GlAccvouch;
import com.ruoyi.erp.service.IGlAccvouchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 凭证生成Controller
 * 
 * @author ztj
 * @date 2023-04-28
 */
@RestController
@RequestMapping("/erp/accvouch")
public class GlAccvouchController extends BaseController
{
    @Autowired
    private IGlAccvouchService glAccvouchService;

    /**
     * 查询凭证生成列表
     */
    @PreAuthorize("@ss.hasPermi('erp:accvouch:list')")
    @GetMapping("/list")
    public TableDataInfo list(GlAccvouch glAccvouch)
    {
        startPage();
        List<GlAccvouch> list = glAccvouchService.selectGlAccvouchList(glAccvouch);
        return getDataTable(list);
    }

    /**
     * 导出凭证生成列表
     */
    @PreAuthorize("@ss.hasPermi('erp:accvouch:export')")
    @Log(title = "凭证生成", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GlAccvouch glAccvouch)
    {
        List<GlAccvouch> list = glAccvouchService.selectGlAccvouchList(glAccvouch);
        ExcelUtil<GlAccvouch> util = new ExcelUtil<GlAccvouch>(GlAccvouch.class);
        util.exportExcel(response, list, "凭证生成数据");
    }

    /**
     * 获取凭证生成详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:accvouch:query')")
    @GetMapping(value = "/{iYear}")
    public AjaxResult getInfo(@PathVariable("iYear") String iYear)
    {
        return success(glAccvouchService.selectGlAccvouchByIYear(iYear));
    }

    /**
     * 新增凭证生成
     */
    @PreAuthorize("@ss.hasPermi('erp:accvouch:add')")
    @Log(title = "凭证生成", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GlAccvouch glAccvouch)
    {
        return toAjax(glAccvouchService.insertGlAccvouch(glAccvouch));
    }

    /**
     * 修改凭证生成
     */
    @PreAuthorize("@ss.hasPermi('erp:accvouch:edit')")
    @Log(title = "凭证生成", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GlAccvouch glAccvouch)
    {
        return toAjax(glAccvouchService.updateGlAccvouch(glAccvouch));
    }

    /**
     * 删除凭证生成
     */
    @PreAuthorize("@ss.hasPermi('erp:accvouch:remove')")
    @Log(title = "凭证生成", businessType = BusinessType.DELETE)
	@DeleteMapping("/{iYears}")
    public AjaxResult remove(@PathVariable String[] iYears)
    {
        return toAjax(glAccvouchService.deleteGlAccvouchByIYears(iYears));
    }
}
